const path = require('path')
const router = require('koa-router')()
const Sequelize = require('sequelize')
const fileModel = require('../../models/file')
const jwt = require('jsonwebtoken')

const dao = require('../../dao/' + path.basename(__dirname))

const routerUploadAndDownloadVariable = require('../../config/file_service')

// 此jwtPassword仅是Upload和Download路由所使用的常量
const jwtPassword = routerUploadAndDownloadVariable.jwtPassword

router.get('/', async (ctx, next) => {
    try {

        const data = ctx.request.query
        const inform = {
            file_id : data.file_id,
        }

        const token = jwt.sign(
            inform,
            jwtPassword, {
                expiresIn: 3600
            })

        // 路由响应
        ctx.status = 200
        ctx.body = token

    }
    catch (err) {
        ctx.status = 500
        ctx.body = {
            message: err.message
        }
        // await next()
    }
})


module.exports = router.routes();